@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

if "%~1"=="" (
    echo Please provide a prefix, e.g.:
    echo    dabao.bat dev
    exit /b 1
)

set PREFIX=%~1
set JAR_NAME=cement-0.0.1.jar
set JAR_DIR=%cd%\target
set NEW_JAR=%PREFIX%%JAR_NAME%
set NEW_JAR_PATH=%JAR_DIR%\%NEW_JAR%

echo [1] Start building project...
call mvnd clean compile test package

if errorlevel 1 (
    echo Build failed. Exiting.
    exit /b 1
)

if not exist "%JAR_DIR%\%JAR_NAME%" (
    echo File not found: %JAR_DIR%\%JAR_NAME%
    exit /b 1
)

echo [2] Renaming jar to: %NEW_JAR%
copy /Y "%JAR_DIR%\%JAR_NAME%" "%NEW_JAR_PATH%" >nul

echo.
echo ✅ Output:
echo    %NEW_JAR_PATH%
echo.
echo 👉 Copy this path to ToDesk file transfer.

endlocal
